package main

import (
	"github.com/streadway/amqp"
	"gitee.com/hlwqds/rabitmqTest/log"
	"time"
)

func main(){
	conn, err := amqp.Dial("amqp://guest:guest@172.17.0.4:5672/")
	log.FailOnError(err, "Failed to connect to RabbitMQ")
	defer conn.Close()

	//创建channel
	ch, err := conn.Channel()
	log.FailOnError(err, "Failed to open a channel")
	defer ch.Close()

	//声明消息队列
	q, err := ch.QueueDeclare(
		"ha.hello1",
		false,
		false,
		false,
		false,
		nil)
	log.FailOnError(err, "Failed to declare a queue")

	for{
		body := "Hello World"
		err = ch.Publish(
			"",
			q.Name,
			false,
			false,
			amqp.Publishing{
				ContentType: "text/plain",
				Body: []byte(body),
			})
		log.FailOnError(err, "Failed to publish a message")
		time.Sleep(time.Second * 1)
	}
}
